package com.zggk.lzz.pdf;


import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zggk.lzz.R;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.callback.FileDialogCallback;
import com.zggk.lzz.mvp.MVPBaseActivity;
import com.github.barteksc.pdfviewer.PDFView;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.io.File;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class PdfActivity extends MVPBaseActivity<PdfContract.View, PdfPresenter> implements PdfContract.View {

    @Bind(R.id.pdfView)
    PDFView pdfView;
    @Bind(R.id.asdf)
    TextView asdf;
    @Bind(R.id.back)
    LinearLayout back;

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_pdf;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        OkGo.<File>post(Urls.JAVASERVER3+"assets/file/browerpdf")
                .params("id", getIntent().getStringExtra("id"))
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token"))
                .execute(new FileDialogCallback(PdfActivity.this) {
                    @Override
                    public void onSuccess(Response<File> response) {
                        pdfView.fromFile(response.body())
                                .defaultPage(1)  //设置默认显示第1页
                                .enableAnnotationRendering(true)
                                .swipeHorizontal(false)
                                .enableSwipe(true)
                                .load();
                    }
                });
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
